<?php
/**
 * Created by PhpStorm.
 * User: yiyu
 * Email: smalleasyu@gmail.com
 * Date: 2020-01-30 12:48:32
 * Desc:
 */

namespace app\base\model\user;

use think\Model;
use think\Db;

class UserStatisticsInfo extends Model
{

    // 关闭自动写入时间戳
    protected $autoWriteTimestamp = false;

    protected $table = 'xy_user.xy_user_statistics_info';

    public static function userStatistics($user_id, $field, $num = 1)
    {
        $user_statistics_info = self::find($user_id);
        if (empty($user_statistics_info)) {
            return self::create(['user_id' => $user_id, $field => 1, 'create_time' => date('Y-m-d H:i:s')]);
        } else {
            return self::where('user_id', $user_id)->update([$field => Db::raw("{$field}+{$num}"), 'update_time' => date('Y-m-d H:i:s')]);
        }
    }

}